package com.jl.card.parse.part.p1p2;

public class ParamTool {
	
	private static final String SEP = "|";

	public static String getSelectDescript(byte p1,byte p2){
		StringBuilder sb = new StringBuilder();
		if(p1 == (byte)0b0000_0000){
			sb.append("Select DF, EF or MF by file id").append(SEP);
		}else if(p1 == (byte)0b0000_0001){
			sb.append("Select child DF of the current DF").append(SEP);
		}else if(p1 == (byte)0b0000_0011){
			sb.append("Select parent DF of the current DF").append(SEP);
		}else if(p1 == (byte)0b0000_0100){
			sb.append("Selection by DF name").append(SEP);
		}else if(p1 == (byte)0b0000_1000){
			sb.append("Select by path from MF").append(SEP);
		}else if(p1 == (byte)0b00001001){
			sb.append("Select by path from current DF").append(SEP);
		}
		if(p1 == (byte)0b00000100){
			sb.append("Application session control : ");
			if((p2 & 0b0110_0000) == 0){
				sb.append("Activation/Reset");
			}else if((p2 & 0b01100000) == 0b0100_0000){
				sb.append("Termination");
			}
			sb.append(SEP);
		}
		if((p2 & 0b1001_1100) == 0b0000_0100){
			sb.append("Return FCP template").append(SEP);
		}
		if((p2 & 0b1001_1100) == 0b0000_1100){
			sb.append("No data returned").append(SEP);
		}
		switch (p2 & 0b1001_0011) {
		case 0b0000_0000:
			sb.append("First or only occurrence");
			break;
		case 0b0000_0001:
			sb.append("Last occurrence");
			break;
		case 0b0000_0010:
			sb.append("Next occurrence");
			break;
		case 0b0000_0011:
			sb.append("Previous occurrence");
			break;
		}
		return sb.toString();
	}

	public static String getReadOrUpdateBinaryDescript(byte p1, byte p2) {
		StringBuilder sb = new StringBuilder();
		if((p1 & 0b1000_0000) == 0){
			sb.append("offset:");
			sb.append("" + (((p1<< 8) | p2) & 0x7FFF));
		}else{
			sb.append("SFI:").append("" + (p1 & 0b0001_1111)).append(SEP);
			sb.append("offset:");
			sb.append("" + (p2 & 0x7FFF));
		}
		return sb.toString();
	}

	public static String getReadOrUpdateRecordDescript(byte p1, byte p2) {
		StringBuilder sb = new StringBuilder();
		if((p1 & 0b1111_1000) == 0){
			sb.append("Currently selected EF");
		}else{
			sb.append("SFI:").append("" + (p1 & 0b1111_1000));
		}
		sb.append(SEP);
		switch (p1 & 0b0000_0111) {
		case 0b0000_0010:
			sb.append("Next record");
			break;
		case 0b0000_0011:
			sb.append("Previous record");
			break;
		case 0b0000_0100:
			sb.append("Absolute/current mode").append(SEP);
			sb.append("Record number:").append("" + (p1 & 0xFF));
			break;
		}
		return sb.toString();
	}
}
